package com.zrsx.managemodel.mapper;

import com.zrsx.managemodel.common.dto.CreditDTO;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CreditMapper {
    @Select("SELECT score FROM credit_score WHERE user_id = #{userId}")
    Integer getCreditById(Integer userId);

    @Delete("DELETE FROM credit_score WHERE user_id = #{userId}")
    void deleteCredit(Integer userId);

    @Insert("INSERT INTO credit_score(user_id, score, last_update_time) VALUES(#{userId}, #{score}, NOW())")
    void addCredit(CreditDTO creditDTO);

    @Update("UPDATE credit_score SET score = #{score} WHERE user_id = #{userId}")
    void updateCredit(Integer userId,int score);

    @Update("UPDATE credit_score SET score_level = #{newLevel}, last_update_time = NOW() WHERE user_id = #{userId}")
    void updateCreditLevel(Integer userId, int newLevel);
}
